package com.business.sys.service.impl;


import com.business.common.enums.ErrorEnum;
import com.business.common.exception.CustomException;
import com.business.common.utils.StrKit;
import com.business.sys.entity.Config;
import com.business.sys.mapper.ConfigMapper;
import com.business.sys.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 系统配置类:业务接口实现类
 *
 * @author chenjiehong
 * @date 2019-04-28 15:03:18
 * @since 1.0
 */
@Service
public class ConfigServiceImpl implements ConfigService {

    @Autowired
    private ConfigMapper sysConfigMapper;


    @Override
    @Transactional(readOnly = true)
    public Config query(String code) {
        if (StrKit.isBlank(code)) {//参数错误
            throw new CustomException(ErrorEnum.PARAMS_ERROR, "参数名：" + code);
        }
        Config sysConfig = new Config();
        sysConfig.setCode(code);

        Config result = sysConfigMapper.selectOne(sysConfig);
        if (result == null) {//参数错误
            throw new CustomException(ErrorEnum.PARAMS_ERROR, "参数名：" + code);
        }
        return result;
    }

}